package com.cdream.basic.pattern.single;

public class SingleDog {
    // volatile 防止指令重排列，返回个阴间玩意^-^
    private static volatile SingleDog singleDog;
    private String name;
    private SingleDog(){
        this.name = "小白";
    }
    // 分配内存空间 -> 初始化对象 -> 设置指针
    public static SingleDog createInstance(){
        if (singleDog==null){
            synchronized (SingleDog.class){
                if (singleDog==null){
                    singleDog = new SingleDog();
                }
            }
        }
        return singleDog;
    }

}
